﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Admin.IService;
using Microsoft.AspNetCore.Mvc;

namespace Admin.Web.Controllers.Router
{
    /// <summary>
    /// 用户管理
    /// </summary>
    public class SysUserController : BaseController
    {
        private ISysUserService _sysUserService;
        private ISysRoleService _sysRoleService;
        private ISysUserRoleService _sysUserRoleService;
        public SysUserController(ISysUserService sysUserService, ISysRoleService sysRoleService, ISysUserRoleService sysUserRoleService)
        {
            _sysUserService = sysUserService;
            _sysRoleService = sysRoleService;
            _sysUserRoleService = sysUserRoleService;
        }
        #region 页面路由
        public IActionResult Index()
        {
            return View();
        }
        public async Task<IActionResult> Insert()
        {
            ViewBag.Roles = await _sysRoleService.GetList();
            return View();
        }
        public async Task<IActionResult> Modify(int id)
        {
            var user = await _sysUserService.Get(id);

            ViewBag.RoleId = (await _sysUserRoleService.Get(new { UserId = user.Id }, "UserId=@UserId", "RoleId")).RoleId;
            ViewBag.Roles = await _sysRoleService.GetList();
            return View(user);
        }
        #endregion
    }
}